﻿#include "user.h"
#include <QDebug>

User::User(QObject *parent) : QObject(parent)
{

}

void User::loadFromJsonObject(QJsonObject obj)
{
    id = obj.value("id").toInt();

    username = obj.value("username").toString();
    password = obj.value("password").toString();
    operatePassword = obj.value("operate_password").toString();
    companyId = obj.value("company_id").toString();
    nickName = obj.value("nick_name").toString();
    tel = obj.value("tel").toString();
    mobile = obj.value("mobile").toString();
    position = obj.value("position").toString();
    wechat = obj.value("wechat").toString();
    QQ = obj.value("QQ").toString();
    permission = obj.value("permission").toInt();
    isBoss = obj.value("is_boss").toInt();
    endDate = obj.value("end_date").toString();
    credit = obj.value("credit").toInt();
    upUsername1 = obj.value("up_username1").toString();
    upUsername2 = obj.value("up_username2").toString();
    upUsername3 = obj.value("up_username3").toString();
    upUsername4 = obj.value("up_username4").toString();
    upUsername5 = obj.value("up_username5").toString();

//    Tools::cout("id:"+QString("%1").arg(id));
//    Tools::cout("username:"+username);
//    Tools::cout("password:"+password);
//    Tools::cout("operatePassword:"+operatePassword);
//    Tools::cout("companyId:"+companyId);
//    Tools::cout("nickName:"+nickName);
//    Tools::cout("tel:"+tel);
//    Tools::cout("mobile:"+mobile);
//    Tools::cout("position:"+position);
//    Tools::cout("wechat:"+wechat);
//    Tools::cout("QQ:"+QQ);
//    Tools::cout("permission:"+QString("%1").arg(permission));
//    Tools::cout("isBoss:"+QString("%1").arg(isBoss));
//    Tools::cout("endDate:"+endDate);
//    Tools::cout("credit:"+QString("%1").arg(credit));
//    Tools::cout("upUsername1:"+upUsername1);
//    Tools::cout("upUsername2:"+upUsername2);
//    Tools::cout("upUsername3:"+upUsername3);
//    Tools::cout("upUsername4:"+upUsername4);
//    Tools::cout("upUsername5:"+upUsername5);
}

void User::saveToSettings()
{
    setUsername(username);
    setPassword(password);
    setOperatePassword(operatePassword);
    setCompanyId(companyId);

    setNickName(nickName);
    setPosition(position);
    setTel(tel);
    setMobile(mobile);
    setQQ(QQ);
    setWechat(wechat);
    setCredit(credit);
    setEndDate(endDate);

    setIsBoos(isBoss);
}

QString User::toJson()
{
    return nullptr;
}
